package com.example.forum.controller;

import com.example.forum.common.AppResult;
import com.example.forum.dao.UserMapper;
import com.example.forum.exception.ApplicationException;
import com.example.forum.model.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/test")
@Api(tags = "测试接口")
public class Controller {


    @Autowired
    private UserMapper userMapper;
    //API方法描述
    @ApiOperation(value = "测试接口1")
    @GetMapping("hello")
    public String test(){
        return "这是一个测试的类";
    }

    @ApiOperation(value = "测试接口2")
    @GetMapping("/helloName")
    public AppResult helloName(@RequestParam("name") String name){
        return AppResult.success("你好" + name);

    }

    @ApiOperation(value = "测试接口3，返回一个异常")
    @GetMapping("/exception")
    public String testException() throws Exception {
        throw new Exception("这是⼀个Exception");
    }



    @ApiOperation(value = "测试接口4，返回另一个异常")
    @GetMapping("/appException")
    public String testApplicationException() {
        throw new ApplicationException("这是⼀个⾃定义的ApplicationException");
    }

    @RequestMapping("/test1")
    public AppResult test1(long id){
        User user = userMapper.selectByPrimaryKey(id);
        return AppResult.success(user);


    }

//    @ApiOperation("测试接口1")
//    @RequestMapping("/show1")
//    public String show1(@ApiParam(value = "姓名", required = true, example = "村雨遥")  String name) {
//        return "hello," + name + ",welcome to springboot swagger3！";
//    }


}
